<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
  	<style>
  		html,body{height: 100%;}
      .login-third {margin-top: 3rem;}
      .bg{
        background: white;
  			color:#fff;
  			height: 100%;
  			width: 100%;
  			position: absolute;
      }
  		@media screen and (-webkit-min-device-pixel-ratio:1.5) {
    		.aui-list .aui-list-item {
    			border-bottom: 1px solid #bbb;
    	        background-size: 100% 0px;
    		}
        .aui-bar-nav,.aui-list{background: transparent;}
        .login_input{border: none;background: transparent;}
        .aui-list.aui-form-list .aui-list-item{padding: .1rem;}
        .aui-list.aui-form-list .aui-list-item:active{background: transparent;}

        .login_input input{height: 2.5rem;font-size: 1rem;line-height: 2.5rem;border: none;}
        .aui-list .aui-list-item-label-icon{color:#bbb;}
        /*.login_input .aui-list-item-label-icon,.login_input input{color:#fff;}*/
        .lgbtn{
          /*background: #F73D71 !important;*/
          background:-webkit-linear-gradient(left,#BC4048,#F01768) !important;/* Safari 5.1 - 6.0 */

         background:-o-linear-gradient(right,#BC4048,#F01768) !important;/* Opera 11.1 - 12.0 */

         background:-moz-linear-gradient(right,#BC4048,#F01768) !important;/* Firefox 3.6 - 15 */

         background:linear-gradient(to right,#BC4048,#F01768) !important;/* 标准*/
          color:#fff;border-radius:1.5rem;
        }
        .lgbtn:active{background: #ff435b;color:#fff;}
        .lgbtn.wxbtn{border-color: #F73D71;color:white;}
        .login_input input::-webkit-input-placeholder{color:#bbb;}
        .login_input input:-moz-placeholder{color:#bbb;}
        .login_input input::-moz-placeholder{color:#bbb;}
        .login_input input:-ms-input-placeholder{color:#bbb;}
        .show{display: block;}
        .hide{display: none;}
        /*logo*/
        .logo{
          text-align: center;
        }
        .logo img{
          width: 4.5rem;height: 4.5rem;display:block;margin:0 auto;
        }
        .logo h3{
          margin-top:1.2rem;
        }
        /* close */
        .aui-bar-nav .aui-btn .aui-iconfont{
          color:#959595;
        }
        /* footer */
        .footer{
          position: absolute;bottom: 0;left: 0;width: 100%;
        }
        .footer h6{
          text-align: center;margin: 0.5rem 0;color:#AAAAAA;
        }
        .footer ul {
          height: 30px;width:100%;margin: 1.2rem 0;
        }
        .footer ul li{
          color:#AAAAAA;float: left;width:100%;text-align: center;
        }
        .aui-grid{
          width:90%;margin: 0 auto;
        }
        .wx_login,.mobile_login2{display: none;}
        .aui-btn-outlined:active{background: #F73D71 !important;}
  	</style>
</head>
<body>
	<div class="bg"></div>
	<header class="aui-bar aui-bar-nav" id="header">
        <a class="aui-btn aui-pull-right" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-close"></span>
        </a>
    </header>
    <section class="aui-content aui-margin-t-15 aui-padded-15">
      <div class="logo">
        <img src="../image/Icon.png" alt="">
        <h3>莱特购</h3>
      </div>
    </section>
    <div class="footer">
        <div class="aui-grid wx_login" style="background: none;" onclick="wxauth();">
            <div class="aui-btn aui-btn-block lgbtn wxbtn aui-btn-outlined" tapmode><i class="aui-iconfont aui-icon-wechat"></i>微信登录</div>
        </div>
        <div class="aui-grid mobile_login " style="background: none;" onclick="openPublic(this)" data-frame="login_mobile_frm" data-title="手机登录" tapmode>
            <div class="aui-btn aui-btn-block lgbtn wxbtn aui-btn-outlined" tapmode><i class="aui-iconfont aui-icon-mobile aui-font-size-20"></i>手机登录</div>
        </div>
        <h6 id="xiyi" onclick="openWeb(this)" data-url="" data-title="用户隐私协议" tapmode>登录注册即表示同意<a href="#" style="color:#F73D71;">《用户隐私协议》</a></h6>
        <ul>
          <li class="mobile_login2" onclick="openPublic(this)" data-frame="login_mobile_frm" data-title="手机登录" tapmode><i class="aui-iconfont aui-icon-mobile"></i>手机号登录</li>
        </ul>
        <ul>
          <li class="mobile_login3" onclick="openPublic(this)" data-frame="regist_mobile_frm" data-title="手机注册" tapmode><i class="aui-iconfont aui-icon-mobile"></i>手机注册</li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    var wx;
    apiready = function(){
        api.parseTapmode();
        var header = $api.byId('header');
        $api.fixStatusBar(header);
        wx = api.require('wx');
        var systemType = api.systemType; // 比如： ios
        var appVersion = api.appVersion; // 比如： 1.0.0
        //获取微信登录配置
        _Ajax(window.APIServer.LoignCfg,'post','','json',function(ret){
            if (ret.code==1) {
                var wx = ret.data.wx;
                var apple = ret.data.apple;
                $('#xiyi').attr('data-url',ret.data.user_protocol_url);
                if (wx=='1') {
                    if (systemType=='ios') {
                        if (apple.is_open!='1') {
                            $('.mobile_login').hide();
                            $('.wx_login').show();
                            $('.mobile_login2').show();
                            $('.mobile_login3').show();
                        }else{
                            if (appVersion!=apple.version) {
                                $('.mobile_login').hide();
                                $('.wx_login').show();
                                $('.mobile_login2').show();
                                $('.mobile_login3').show();
                            }
                        }
                    }else{
                        $('.mobile_login').hide();
                        $('.wx_login').show();
                        $('.mobile_login2').show();
                        $('.mobile_login3').show();
                    }
                }
            }
        });

    };
    //微信登录
    function wxauth(){
        //是否安装客户端
        wx.isInstalled(function(ret, err) {
            if (!ret.installed) {
                alert('您还没安装微信客户端');
                return false;
            }else{
                //step1 获取code...
                wx.auth({
                    apiKey: ''
                }, function(ret, err) {
                    //step get access_token
                    if (ret.status) {
                        _loading('登录中...','',true);
                        wx.getToken({
                            apiKey: '',
                            apiSecret: '',
                            code: ret.code
                        }, function(ret, err) {
                            if (ret.status) {
                                //step3 getuserinfo
                                wx.getUserInfo({
                                    accessToken: ret.accessToken,
                                    openId: ret.openId
                                }, function(ret, err) {
                                    if (ret.status) {
                                        //last 提交服务器验证
                                        var uinfo = ret;
                                        uinfo.device_model = api.deviceModel;
                                        uinfo.device_id = api.deviceId;
                                        _Ajax(window.APIServer.WxLogin,'post',{values:uinfo},'json',function(ret){
                                            _loading_close();
                                            //console.log(JSON.stringify(ret))
                                            if (ret.code==1) {
                                                var uinfo = ret.data;
                                                if (uinfo.is_bind_mobile==0) {
                                                    var frame = {
                                                        'title':'绑定手机',
                                                        'framename':'bind_mobile_frm',
                                                        'is_login_bind':1,
                                                        'token':uinfo.token,
                                                        'uid':uinfo.uid,
                                                        'uinfo':uinfo
                                                    }
                                                    openPublic(JSON.stringify(frame));
                                                }else{
                                                    //存储用户信息
                                                    _SetPrefs('token', uinfo.token);
                                                    _SetPrefs('uid', uinfo.uid);
                                                    _SetPrefs('uinfo', uinfo);

                                                    // 登录成功后 设置别名 API 阿春儿 1223
                                                    var ajpush = api.require('ajpush');
                                                    var param = {alias:uinfo.uid};
                                                    ajpush.bindAliasAndTags(param,function(ret) {
                                                         var statusCode = ret.statusCode;
                                                          /*alert('处理结果：\n' + JSON.stringify(ret));*/
                                                    });

                                                    /*alert('绑定结果\n' + JSON.stringify(param));*/

                                                    //广播事件：用户登录成功
                                                    _SendEvent('UserLogin', uinfo.uid);
                                                    _toast('登录成功！');
                                                    setTimeout(function() {
                                                         api.closeToWin({
                                                             name : 'root'
                                                         });
                                                    }, 500)
                                                }
                                            }else if (ret.code==2) {
                                                api.openWin({
                                                    name: 'invite_code_frm'
                                                    ,url: 'widget://html/invite_code_frm.html'//
                                                    ,allowEdit:true
                                                    ,pageParam: {
                                                        wxinfo: ret.data
                                                    }
                                                });
                                            }else{
                                                _toast(ret.msg);
                                            }

                                        });
                                    } else {
                                        _loading_close();
                                        _toast('获取信息失败');
                                    }
                                });
                            } else {
                                _loading_close();
                                _toast('登录失败');
                            }
                        });
                    } else {
                        var code_arr = {'-1':'未知错误','1':'您取消了登录','2':'您拒绝了登录','3':'微信未安装'};
                        _toast(code_arr[err.code]);
                    }
                });
            }
        });

    }
</script>
</html>
